package com.atguigu.guli.service.edu.controller.admin;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Course;
import com.atguigu.guli.service.edu.entity.CourseDescription;
import com.atguigu.guli.service.edu.entity.form.CourseInfoForm;
import com.atguigu.guli.service.edu.entity.query.CourseQuery;
import com.atguigu.guli.service.edu.entity.vo.CourseVo;
import com.atguigu.guli.service.edu.service.CourseDescriptionService;
import com.atguigu.guli.service.edu.service.CourseService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2021-10-26
 */
@RestController
@CrossOrigin
@RequestMapping("/admin/edu/course")
public class AdminCourseController {

    @Autowired
    CourseService courseService;

    @PostMapping("/save-course-info")
    public R saveCourseInfo(@RequestBody CourseInfoForm courseInfoForm){
        String courseId = courseService.saveCourseInfo(courseInfoForm);
        return R.ok().data("id",courseId);
    }

    @GetMapping("/getById/{id}")
    public R getById(@PathVariable String id){
        CourseInfoForm courseInfoForm = courseService.getCourseInfoById(id);
        if(courseInfoForm!=null){
            return R.ok().data("courseInfoForm",courseInfoForm);
        }else{
            return R.error().message("查找的数据不存在！");
        }
    }
    @PutMapping("/update")
    public R update(@RequestBody CourseInfoForm courseInfoForm){

        courseService.updateCourseInfo(courseInfoForm);

        return R.ok().message("更新信息成功");
    }

    @GetMapping("/list/{pageNum}/{pageSize}")
    public R list(@PathVariable Integer pageNum, @PathVariable Integer pageSize,
                  CourseQuery courseQuery){
        IPage<CourseVo> page = courseService.selectPage(pageNum,pageSize,courseQuery);
        return R.ok().data("list",page);
    }
}

